var API = API || {};

API.x_pager = {
    PagerManager: function (results_container, item_container_id, effects_manager) {
        var parent = this;

        var results_container = results_container;
        var item_container_id = item_container_id;
        var search_list = search_list;

        var myEffects_manager = effects_manager;

        $.fn.preBind = function (type, data, fn) {
            this.each(function () {
                var $this = $(this);

                $this.bind(type, data, fn);

                var currentBindings = $._data(this, "events")[type];
                if ($.isArray(currentBindings)) {
                    currentBindings.unshift(currentBindings.pop());
                }
            });
            return this;
        };

        this.Init = function () {

            $(results_container).pajinate({
                items_per_page: 10,
                item_container_id: item_container_id,
                wrap_around: false,
                nav_label_first: '<<<',
                nav_label_last: '>>>',
                nav_label_prev: '<<',
                nav_label_next: '>>',
                num_page_links_to_display: 7,
                show_first_last: false
            });

            // On each reload reset the pagination on click handler
            $(".page_link").preBind("click", function () {

                if (API.Data.IS_FILTERING === true || $(this).hasClass('active_page')) {
                    return false;
                }
                myEffects_manager.execEffect();
            });
            $(".previous_link").preBind("click", function () {
                if (API.Data.IS_FILTERING === true || $(this).hasClass('active_page')) {
                    return false;
                }
                myEffects_manager.execEffect();
            });
            $(".next_link").preBind("click", function () {
                if (API.Data.IS_FILTERING === true || $(this).hasClass('active_page')) {
                    return false;
                }
                myEffects_manager.execEffect();
            });

        }
    }
};
